package jee.boot.entity.bpm;

import com.google.common.collect.Maps;
import jee.boot.common.utils.MapUtils;
import jee.boot.common.utils.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * 表单设计_业务表列
 */
public class BusinessColumn {
    /**
     * 属性名称(列名称的驼峰转换形式)
     */
    private String fieldName;
    /**
     * 列名称(一般为下划线分隔多个单词)
     */
    private String columnName;
    /**
     * 备注
     */
    private String comment;
    /**
     * 是否必填
     */
    private String required = BpmConstant.SYS_NO;
    /**
     * 数据类型 字典:column_data_type
     */
    private String dataType = BpmConstant.BPM_COLUMN_DATA_TYPE_STRING;
    /**
     * 数据长度
     */
    private Integer length = 64;
    /**
     * 数据精度
     */
    private Integer accuracy = 0;
    /**
     * 默认值
     */
    private String defaultValue;
    /**
     * 是否是主键
     */
    private String primaryKey = BpmConstant.SYS_NO;
    /**
     * 是否需要创建字段,(比如一些统计字段,或者附件关联字段,在某些场景是不需要存储数据库的)
     */
    private String create = BpmConstant.SYS_YES;
    /**
     * 排序
     */
    private Integer sort = 0;
    /**
     * 是否是审计字段
     */
    private String auditField=BpmConstant.SYS_NO;
    /**
     * 校验规则,可多选,使用逗号隔开 字典: column_data_validation
     */
    private List<String> dataValidation;
    /**
     * 字段控件: 字典: column_field_control
     */
    private String controlType;
    /**
     * 控件配置
     */
    private Map<String,Object> setting= Maps.newHashMap();

    public BusinessColumn() {
    }

    public String getFieldName() {
        if(StringUtils.isBlank(fieldName)){
            return StringUtils.toCamelCase(columnName);
        }
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getRequired() {
        return required;
    }

    public void setRequired(String required) {
        this.required = required;
    }

    public void setPrimaryKey(String primaryKey) {
        this.primaryKey = primaryKey;
    }

    public void setCreate(String create) {
        this.create = create;
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public Integer getAccuracy() {
        return accuracy;
    }

    public void setAccuracy(Integer accuracy) {
        this.accuracy = accuracy;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public String getPrimaryKey() {
        return primaryKey;
    }

    public String getCreate() {
        return create;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public List<String> getDataValidation() {
        return dataValidation;
    }

    public void setDataValidation(List<String> dataValidation) {
        this.dataValidation = dataValidation;
    }

    public String getControlType() {
        return controlType;
    }

    public void setControlType(String controlType) {
        this.controlType = controlType;
    }

    public String getAuditField() {
        return auditField;
    }

    public void setAuditField(String auditField) {
        this.auditField = auditField;
    }

    public Map<String, Object> getSetting() {
        return setting;
    }

    public void setSetting(Map<String, Object> setting) {
        this.setting = setting;
    }

    public String getDictionaryType() {
        Map<String, Object> setting = getSetting();
        if(setting!=null && setting.containsKey("dictionary")){
            return MapUtils.getValue(setting,"dictionary");
        }
        return null;
    }

    public String getFormat() {
        Map<String, Object> setting = getSetting();
        if(setting!=null && setting.containsKey("format")){
            return MapUtils.getValue(setting,"format");
        }
        return null;
    }
}
